Telegram Group & Telegram Channel
Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.



tg-me.com/python_job_interview/1070
Create:
Last Update:

Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.

BY Python вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_job_interview/1070

View MORE
Open in Telegram


Python вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

The STAR Market, as is implied by the name, is heavily geared toward smaller innovative tech companies, in particular those engaged in strategically important fields, such as biopharmaceuticals, 5G technology, semiconductors, and new energy. The STAR Market currently has 340 listed securities. The STAR Market is seen as important for China’s high-tech and emerging industries, providing a space for smaller companies to raise capital in China. This is especially significant for technology companies that may be viewed with suspicion on overseas stock exchanges.

Python вопросы с собеседований from ye


Telegram Python вопросы с собеседований
FROM USA